home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 371_01 / using.doc < prev    next >
Text File  |  1992-05-08  |  37KB  |  948 lines

  1.     USERS GUIDE TO WINDOSIO
  2.  
  3. WinDosIO is a powerful dynamic link library which allows structured programming, terminal IO and established graphics routines to work under Microsoft Windows.  Yet the full Windows API is always available. Your programs can constitute any combination of the structured and event driven paradigms. Many DOS programs can be ported to Windows without changing a single line of code!
  4.  
  5.  
  6. Getting Started
  7.  
  8. The easiest way to use WinDosIO is to let WinDosIO take care of all  the Windows functions for you. Take a look at EXAMPL2, included on the distribution disk and printed below.
  9.  
  10.  
  11. /***************************************************************************
  12. * EXAMPL2.C
  13. * Hello World
  14. **************************************************************************/
  15.  
  16. #include <WinDosIO.h>
  17.  
  18. main()
  19.  {
  20.     printf("Hello, World\n");
  21.         return 0;
  22.  }
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. Look familiar? Its the classic "Hello, World" program for beginning C programmers. Have you ever seen the Window's version of this simple program? It goes on for several pages. Yet the WinDosIO version of this program looks exactly like the DOS or UNIX version with one exception. Instead of including <stdio.h>, <WinDosIO.h> was included. That is only because this program can be compiled under any memory model. However, since printf is located in the WinDosIO DLL, it is always far(a 4 byte address). If you compile with the large memory model then <stdio.h> can be included instead of <WinDosIO.h>.  In that case, "Hello, World" converts from DOS to Windows with no changes at all to the code! It can be resized, moved, and up to 32 instances can be run at once. 
  30.  
  31.  
  32. It Isn't Magic
  33.  
  34. Part of the secret behind the seamless conversion is a source module WinDosIO.C, included on the distribution disk. You compile and link this module with your DOS style program and the WinDosIO import library. A compiler which includes the Window's Software Development Kit is also required. By following the sample compile and link instructions below, you now know enough to begin converting DOS programs to Microsoft Windows.
  35.  
  36.  
  37. WinDosIO.C, The Secret Unfolds
  38.  
  39. Experienced users of WinDosIO will want to take advantage of  Microsoft Windows capabilities to enhance their programs ported over from DOS. Understanding  how to integrate the environments, requires a basic understanding of WinDosIO.C
  40.  
  41. /***************************************************************************
  42. *  WinDosIO WinMain Module - By compiling this module and linking with your
  43. *  DOS application in C or C++, most DOS applications can be run under
  44. *  Microsoft Windows with no changes at all(The header file WinDosIO.h
  45. *  should be included to eliminate warnings and even potential errors
  46. *  if not compiling with the large model!)
  47. *  For WinDOSIO Version 2.0 BETA
  48. *  Copyright Graubart-Cervone Software 1991,1992
  49. *****************************************************************************/
  50. #include <windows.h>
  51. #include <string.h>
  52.  
  53. #include <WinDosIO.h>
  54.  
  55.  
  56. #define MAXARGS 16
  57.  
  58. #define MAX_CMDLINE 128
  59.  
  60. int pascal WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  61.            LPSTR lpszCmdline, int cmdshow)
  62.  
  63.  {
  64.     struct CWS cws;
  65.     struct CWS far *cwsP;
  66.     char cmdLineBuffer[MAX_CMDLINE];
  67.     HWND hwnd;
  68.     MSG msg;
  69.     RECT r;
  70.     char *argv[MAXARGS];
  71.     int argc;
  72.     short i;
  73.  
  74.     /* Adapt to any memory model */
  75.     for (i = 0; i < MAX_CMDLINE; i++)
  76.         if (!(cmdLineBuffer[i] = *lpszCmdline++)) break;
  77.       /* Initialize terminal IO */
  78.     WinDosIO(WD_INIT,hInstance,0);
  79.     WinDosIO(WD_REGISTER_WINDOW,hPrevInstance,0);
  80.     hwnd = WinDosIO(WD_CREATE_MAIN_WINDOW,cmdshow,
  81.                     (long)((LPSTR)"WinDosIO"));
  82.  
  83.     GetClientRect(hwnd,&r);
  84.  
  85.  
  86.     cws.cwsTop = r.top;
  87.     cws.cwsLeft = r.left;
  88.     cws.cwsXSize = r.right - r.left;
  89.     cws.cwsYSize = r.bottom - r.top;
  90.     cws.cwsTitle = "";
  91.     cws.cwsFlags = 0;
  92.     cwsP = &cws;
  93.     WinDosIO(WD_CREATE_CHILD_WINDOW,0,(unsigned long)cwsP);
  94.     argv[0] = "WinDosIO";
  95.     if (argv[argc=1] = strtok(cmdLineBuffer," "))
  96.        for (argc = 2; argc < MAXARGS; argc++)
  97.         if (!(argv[argc] = strtok(NULL," "))) break;
  98.  
  99.     main(argc,argv);
  100.  
  101.  
  102.  
  103.     /* Use WinDosIO(WD_DESTROY,hwnd, 0); to terminate application
  104.        without having to click on system close icon.
  105.     */
  106.  
  107.     while( GetMessage( &msg, 0, 0, 0 ) != 0 )
  108.          {
  109.         TranslateMessage( &msg );
  110.         DispatchMessage( &msg );
  111.          }
  112.  
  113.     return 0;
  114.  }
  115.  
  116.  
  117.  
  118.  
  119. Notice the #include files at the top include both <windows.h> and <WinDosIO.h>. Windows.h is included with the Window's Software Development Kit. The #define's indicate that up to 16 command line arguments can be given(15 plus the program name) in a command line not to exceed 128 characters. 
  120.  
  121.  
  122. The WinMain routine is the high level routine of all Windows programs in C and C++. It is declared as returning an integer and following the Pascal calling convention for its arguments. The function is called with four arguments. The first, hInstance is a unique instance handle for this particular instance of the program. The second argument hPrevInstance is non-zero if at least one previous instance of the program is currently executing. The third argument is the command line used to execute the program. The fourth indicates how to initially display the main window.
  123.  
  124. WinDosIO.C must convert the command line into standard argc, argv format. To parse in a memory model consistent manner, the command line is first moved onto the stack.
  125.  
  126.  
  127. Next the WinDosIO DLL is initialized with the instance handle of the program. Without this initialization call , WinDosIO(WD_INIT, hInstance, 0) , no other WinDosIO functions will operate properly. If you write your own WinMain function, you must initialize WinDosIO before using any of the functions.
  128. Every Windows program has at least one window, often called the main or high level window. Associated with this window is a window procedure which handles messages sent by Windows itself. To create this main window two WinDosIO function calls are required. The first WinDosIO(WD_REGISTER_WINDOW, hPrevInstance, 0) associates certain properties,  including the window procedure with the WinDosIO window class. hPrevInstance is an argument, because this is only done if not previously done by another instance of the program currently running. Having registered the WinDosIO window class, the main window itself is created. This is done with a call to  WinDosIO(WD_CREATE_MAIN_WINDOW, cmdshow, windowTitle). The windowTitle must be a far pointer to a character string cast as a long. The example shows how to do this with a simple string. 
  129.  
  130.  
  131. This is all well and good for many programs, however, as you gain proficiency in Window's programming, you will want to create your own main window and enhance the window procedure for additional functionality. Here is the code which is executed in the DLL when these two WinDosIO functions are executed.
  132.  
  133.  
  134.  
  135.  
  136.  
  137. // Some of the constructs, such as this comment are in C++
  138.  
  139. long far pascal WndProc(HWND, WORD, WORD, LONG);
  140.  
  141. // Called when WinDosIO(WD_REGISTER_WINDOW,...) is called
  142. static void RegisterWindow(HANDLE hPrevInstance)
  143.  {
  144. // Check to insure application has been registered
  145. // If user registers their own window, this is not required 
  146.     AI = GetAppinfo();
  147.     if (!AI)
  148.        Exit(DOSCOM,1);
  149. // If another instance of the program has not already registered
  150. // the window class. 
  151.     if (!hPrevInstance)
  152.      {
  153.         WNDCLASS wc;
  154.         wc.style = 0;
  155.         wc.lpfnWndProc = WndProc; // Window procedure
  156.         wc.cbClsExtra = 0;
  157.         wc.cbWndExtra = 0;
  158.         wc.hInstance = AI->hInst;
  159.         wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
  160.         wc.hCursor = LoadCursor( 0, IDC_ARROW );
  161.         wc.hbrBackground = COLOR_WINDOW + 1;
  162.         wc.lpszMenuName = "WinDosIO";
  163.         wc.lpszClassName = "WinDosIO"; // Class Name
  164.         RegisterClass( &wc );
  165.       }
  166.  }
  167.  
  168. // Called when WinDosIO(WD_CREATE_MAIN_WINDOW,...) is called
  169. static HWND CreateMainWindow(short cmdshow, char *title)
  170.  {
  171.     AI = GetAppinfo();
  172.     if (!AI)
  173.     Exit(DOSCOM,3);
  174.     HWND hwnd = CreateWindow(
  175.    "WinDosIO",  // The window class registered above
  176.        title,
  177.        WS_OVERLAPPEDWINDOW,
  178.         CW_USEDEFAULT,  0,  CW_USEDEFAULT, 0,
  179.          0,